public class FindMin {
    // leetcode 寻找旋转排序数组中的最小值
    // https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/description/?envType=study-plan-v2&envId=top-100-liked
    public int findMin(int[] nums) {
        int n = nums.length;
        if (n == 1) return nums[0];
        int left = 0, right = n - 1;
        while (left < right) {
            // left-right之间都是有序的，直接返回nums[left]
            if (nums[right] > nums[left]) return nums[left];
            int mid = left + (right - left) / 2;
            if (nums[0] <= nums[mid]) {
                // 说明mid左侧有序，那么最小值就出现在mid右边部分
                left = mid + 1;
            }else {
                right = mid;
            }
        }
        return nums[left];
    }
}
